
import axios from "axios"

axios.interceptors.request.use(cfg=>{
    const token = localStorage.getItem("token")
    if(token){
        cfg.headers.authorization=token
    }
    return cfg
})
axios.interceptors.response.use(res=>{
    if(res.data.token){
        localStorage.setItem("token",res.data.token)
    }
    if(res.data.name === "JsonWebTokenError"){
        localStorage.removeItem("token")
    }
    return res
    
})
export default axios